<template>
  <div v-loading="loading" element-loading-text="跳转中，请等待...">
    <div class="nav">
      <div class="info_paln">
        <div class="title">账户余额</div>
        <div class="num">
          <span>￥</span
          ><span>{{
            (userInfo && formatCurrency(userInfo.ye)) || "0.00"
          }}</span>
        </div>
        <button class="btn" @click="show = true">余额充值</button>
      </div>
      <div class="nav_plan container">
        <div
          :class="tagsIdx == index ? 'a_nav_tags' : 'nav_tags'"
          v-for="(item, index) in tags"
          :key="item"
          @click="tagsIdx = index"
        >
          {{ item }}
        </div>
      </div>
    </div>
    <div class="box_meng" v-if="show">
      <div class="box_meng_bg">
        <div class="box_meng_title">账户充值</div>
        <div class="box_int">
          <el-input
            placeholder="充值金额（元）"
            type="number"
            v-model.trim="amount"
          />
        </div>
        <div class="footer">
          <el-button @click="show = false" plain size="mini">取消</el-button>
          <el-button
            @click="recharge"
            type="primary"
            size="mini"
            :loading="loading"
            >支付</el-button
          >
        </div>
      </div>
    </div>
    <div class="container">
      <div v-if="tagsIdx === 0">
        <div class="ms_box">
          <el-descriptions :column="1">
            <el-descriptions-item
              label-class-name="my-label"
              v-for="item in descriptions"
              :key="item.k"
              :label="item.t"
            >
              <el-input
                :type="item.k == 'password' ? 'password' : ''"
                readonly
                :value="item.value"
              ></el-input>
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </div>
      <div v-if="tagsIdx === 1">
        <div class="box_wdfb">
          <div class="box_wdfb_title">我的发布</div>
          <div class="labs">
            <el-tabs v-model="wdfbActiveName" @tab-click="wdfbHandleClick">
              <el-tab-pane
                v-for="(item, index) in (itemData && itemData['招标动态']) ||
                []"
                :key="item.lxCode"
                :label="item.lx"
                :name="`${index + 1}`"
              ></el-tab-pane>
            </el-tabs>
            <el-button
              class="btn"
              type="primary"
              icon="el-icon-plus"
              @click="goPublish"
              >我要发布</el-button
            >
          </div>
          <div class="card-body">
            <div class="tishi" v-if="wdfbObj.list.length == 0">暂无数据</div>
            <div class="list" v-for="item in wdfbObj.list" :key="item.noticeId">
              <div class="tiem">
                <div>
                  {{ splitDate(item.fbrq)["month"] }}-{{
                    splitDate(item.fbrq)["day"]
                  }}
                </div>
                <div>{{ splitDate(item.fbrq)["year"] }}</div>
              </div>
              <div class="list_info">
                <div class="list_info_title line_1">
                  {{ item.bt }}
                </div>
                <div class="list_info_dis line_2">
                  {{ item.fbt }}
                </div>
              </div>
              <div class="list_more"></div>
            </div>
            <Pagination
              :page.sync="wdfbObj.pageNum"
              :limit.sync="wdfbObj.pageSize"
              :total="wdfbObj.total"
              @pagination="getListWdfb"
            ></Pagination>
          </div>
        </div>
      </div>
    </div>
    <div v-if="tagsIdx === 2">
      <div class="yemx_box container">
        <div class="yemx_title">余额明细</div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="消费记录" name="first">
            <div
              class="xfjl_list"
              v-for="(item, index) in xfjlObj.list"
              :key="index"
            >
              <div style="display: flex; justify-content: space-around">
                <div class="xfjl_info">
                  <div class="xfjl_name">发布{{ item.bt }}</div>
                </div>
                <div class="xfjl_je">￥-{{ formatCurrency(item.je) }}</div>
              </div>

              <div class="xfjl_tiem" style="color:#afafaf">{{ item.cjsj }}</div>
            </div>
            <Pagination
              :page.sync="xfjlObj.pageNum"
              :limit.sync="xfjlObj.pageSize"
              :total="xfjlObj.total"
              @pagination="getZfjlData"
            ></Pagination>
          </el-tab-pane>
          <el-tab-pane label="充值记录" name="second">
            <div
              class="czjl_list"
              v-for="(item, index) in czjlObj.list"
              :key="index"
            >
              <span style="font-size: 14px; color: #a19d9d"
                >充值时间：{{ item.cjsj }}</span
              ><span
                ><span
                  style="font-size: 15px; "
                  >+￥{{ formatCurrency(item.je) }}</span
                ></span
              >
            </div>
            <Pagination
              :page.sync="czjlObj.pageNum"
              :limit.sync="czjlObj.pageSize"
              :total="czjlObj.total"
              @pagination="getCzjlData"
            ></Pagination>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>
<script>
import index from "../index.vue";
import { splitDate, formatCurrency } from "../../utils/index.js";
export default {
  components: { index },
  data() {
    return {
      show: false,
      amount: "",
      loading: false,
      userInfo: null,
      tags: ["注册信息", "我的发布", "余额明细"],
      tagsIdx: 0,
      descriptions: [
        {
          t: "单位名称（个人姓名)",
          k: "dwmc",
        },
        {
          t: "密码",
          k: "password",
        },
        {
          t: "登录名",
          k: "username",
        },
        {
          t: "统一社会/信用代码",
          k: "xydm",
        },
        {
          t: "申报（经办）人",
          k: "sbr",
        },
        {
          t: "联系电话",
          k: "lxdh",
        },
        {
          t: "用户类型",
          k: "yhlx",
        },
      ],
      activeName: "first",
      // czjlList: [],
      total: 0,
      pageSize: 10,
      pageNum: 1,
      // xfjlList: [],
      itemData: null,
      wdfbActiveName: "1",
      xfjlObj: {
        list: [],
        total: 0,
        pageSize: 10,
        pageNum: 1,
      },
      wdfbObj: {
        list: [],
        total: 0,
        pageSize: 10,
        pageNum: 1,
      },
      czjlObj: {
        list: [],
        total: 0,
        pageSize: 10,
        pageNum: 1,
      },
    };
  },
  created() {
    this.getData();
    this.getZfjlData();
    this.$api.getHomeAPI({}).then((item) => {
      let itemData = item.data;
      this.itemData = itemData;
      this.getListWdfb(itemData["招标动态"][0]);
    });
  },
  methods: {
    goPublish() {
      this.$router.push({
        path: "/publish",
      });
    },
    splitDate(date) {
      return splitDate(date);
    },
    wdfbHandleClick() {
      let { wdfbActiveName, itemData } = this;
      this.getListWdfb(itemData["招标动态"][wdfbActiveName - 1]);
    },
    getListWdfb(row) {
      this.$api.userWdfbAPI({ lxCode: row.lxCode }).then((item) => {
        let { list, total } = item.data;
        this.wdfbObj.list = list;
        this.wdfbObj.total = total;
      });
    },
    handleClick() {
      if (this.activeName == "first") return this.getZfjlData();
      if (this.activeName == "second") return this.getCzjlData();
    },
    getZfjlData() {
      this.$api
        .webUserXfjlAPI({
          pageSize: this.xfjlObj.pageSize,
          pageNum: this.xfjlObj.pageNum,
        })
        .then((res) => {
          let { list, total } = res.data;
          this.xfjlObj.list = list;
          this.xfjlObj.total = total;
        });
    },
    getCzjlData() {
      this.$api
        .webUserCzjlAPI({
          pageSize: this.czjlObj.pageSize,
          pageNum: this.czjlObj.pageNum,
        })
        .then((res) => {
          let { list, total } = res.data;
          this.czjlObj.list = list;
          this.czjlObj.total = total;
        });
    },

    getData() {
      let { descriptions } = this;
      this.$api.userInfoAPI({}).then((item) => {
        let userInfo = item.data;
        for (let i in descriptions) {
          this.$set(descriptions[i], "value", userInfo[descriptions[i].k]);
        }
        this.userInfo = userInfo;
      });
    },
    recharge() {
      let { amount } = this;
      if (amount <= 0) {
        this.$message.error("输入金额错误");
        return;
      }
      this.loading = true;
      this.$api
        .webUserCzAPI({
          je: amount,
          subject: "西部招标交易采购平台",
        })
        .then(
          (item) => {
            this.show = false;
            const div = document.createElement("div");
            div.innerHTML = item.data;
            document.body.appendChild(div);
            document.forms[0].submit();
            setTimeout(() => {
              this.loading = false;
            }, 1500);
          },
          () => {
            this.loading = false;
          }
        );
    },
    //验证金额是否正确
    formatCurrency(val) {
      return formatCurrency(val);
    },
  },
};
</script>
<style scoped>
.tishi {
  text-align: center;
  margin: 42px;
}
.list {
  display: flex;
  align-items: center;
  padding: 31px;
  border-bottom: 1px solid #e5e5e5;
  /* height: 60px; */
}
.list .tiem {
  width: 60px;
  height: 60px;
  background: #f8f8f8;
  flex-shrink: 0;
  margin-right: 30px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #000000;
}
.list:hover .tiem {
  color: rgb(255, 255, 255);
  background: #2959b0;
}
.list .tiem div:nth-child(1) {
  margin-bottom: 13px;
}
.list .tiem div:nth-child(2) {
  font-size: 12px;
}
.list .list_info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-right: 31px;
}
.list .list_info .list_info_title {
  font-size: 18px;
  font-weight: 700;
  color: #333333;
}
.list:hover .list_info .list_info_title {
  color: #2959b0;
}
.list .list_info .list_info_dis {
  margin-top: 21px;
  font-size: 14px;
  color: #9e9e9e;
  line-height: 20px;
}
.list:hover .list_more {
  background-image: url("@/static/icon/jy_icon_hover.png");
}
.list .list_more {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-image: url("@/static/icon/jy_icon.png");
  background-repeat: no-repeat;
  background-size: contain;
}
.box_wdfb {
  background: #ffffff;
  border: 1px solid #ececec;
  box-shadow: 6px 6px 10px 0px rgba(0, 0, 0, 0.04);
  margin: 51px auto;
  padding: 41px;
}
.box_wdfb_title {
  font-weight: 700;
  font-size: 24px;
  margin-bottom: 31px;
}
.labs {
  position: relative;
}
.labs .btn {
  position: absolute;
  right: 0;
  top: -15px;
}
.xfjl_list {
  padding: 15px;
  border-bottom: 1px solid #ececec;
}
.xfjl_list .xfjl_info {
  flex: 1;
  display: flex;
}
.xfjl_list .xfjl_info .xfjl_name {
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 16px;
  margin-right: 31px;
}
.xfjl_list .xfjl_info .xfjl_time {
  color: #9e9e9e;
  font-size: 13px;
}
.xfjl_list .xfjl_je {
  font-size: 14px;
}
.xfjl_list .xfjl_info .xfjl_tiem {
  font-size: 14px;
  color: #b8b8b8;
  margin-right: 15px;
}
.yemx_box {
  background: #ffffff;
  border: 1px solid #ececec;
  box-shadow: 6px 6px 10px 0px rgba(0, 0, 0, 0.04);
  margin: 51px auto;
  padding: 41px;
}
.yemx_box .yemx_title {
  font-weight: 700;
  font-size: 24px;
  margin-bottom: 31px;
}
.yemx_box .czjl_list {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f5f5f5;
  padding: 15px 0;
}
::v-deep .my-label {
  width: 149px !important;
  text-align: end;
}
.ms_box {
  margin: 0 auto;
  width: 500px;
  margin: 51px auto;
}
.nav {
  display: flex;
  flex-direction: column;
}
.nav_plan {
  margin: 0 auto;
  width: 30%;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
}
.nav_plan .nav_tags {
  font-size: 16px;
  color: #000000;
}
.nav_plan .a_nav_tags {
  font-size: 16px;
  color: #2959b0;
  padding-bottom: 30px;
  border-bottom: #2959b0 3px solid;
}
.box_meng {
  background-color: rgba(0, 0, 0, 0.7);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  z-index: 100;
}
.box_meng_bg {
  background-color: white;
  width: 307px;
  margin: 0 auto;
  margin-top: 15vh;
  border-radius: 5px;
  padding: 31px;
}
.box_meng_bg .box_meng_title {
  font-weight: bold;
  font-size: 18px;
  text-align: center;
  margin-bottom: 31px;
}
.box_meng_bg .footer {
  text-align: end;
  margin-top: 31px;
}
.nav {
  height: 332px;
  background-image: url("@/static/img/pexels-photo-2387797@2x.png");
  background-repeat: no-repeat;
  background-size: cover;
}
.nav .info_paln {
  padding-top: 0vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
}
.nav .info_paln .title {
  color: #a1a1a1;
  font-size: 12px;
  text-align: center;
}
.nav .info_paln .num {
  text-align: center;
  margin: 21px;
  font-weight: bold;
}
.nav .info_paln .num span:nth-child(1) {
  font-size: 22px;
  color: #000000;
}
.nav .info_paln .num span:nth-child(2) {
  font-size: 36px;
}
.nav .info_paln .btn {
  width: 162px;
  height: 46px;
  background: #2959b0;
  border-radius: 23px;
  color: white;
}
</style>